// ignore_for_file: unused_field

import 'package:flutter/material.dart';
import 'package:rabbit/pages/cart/cart_page.dart';
import 'package:rabbit/pages/category/category_page.dart';
import 'package:rabbit/pages/mine/mine_page.dart';
import 'package:rabbit/pages/home/home_page.dart';

class RootPage extends StatefulWidget {
  const RootPage({super.key});

  @override
  State<RootPage> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  ///定义页面列表
  List pageList = [HomePage(), CategoryPage(), CartPage(), MinePage()];
  // 默认选中的item
  int _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // 页面内容
        body: pageList[_currentIndex],
        // 底部导航
        bottomNavigationBar: Theme(
            // 覆盖子组件的主题色
            data: ThemeData(
                //短按时透明色
                splashColor: Color.fromARGB(0, 0, 0, 0),
                //长按时透明色
                highlightColor: Color.fromARGB(0, 0, 0, 0)),
            child: BottomNavigationBar(
              // 统一选中及未选中的字号大小
              selectedFontSize: 10,
              unselectedFontSize: 10,
              //设置选中及未选中时的文字颜色
              selectedItemColor: Color(0xFF3CCEAF),
              unselectedItemColor: Color(0xFF383838),
              // 默认选中的item
              currentIndex: _currentIndex,
              // 监听item的点击事件
              onTap: (int index) {
                setState(() {
                  _currentIndex = index;
                });
              },
              type: BottomNavigationBarType.fixed,
              items: [
                //首页
                BottomNavigationBarItem(
                    icon: Image.asset('assets/home_nor.png',
                        gaplessPlayback: true),
                    activeIcon: Image.asset('assets/home_sel.png',
                        gaplessPlayback: true),
                    label: '首页'),
                //分类
                BottomNavigationBarItem(
                    icon: Image.asset('assets/category_nor.png',
                        gaplessPlayback: true),
                    activeIcon: Image.asset('assets/category_sel.png',
                        gaplessPlayback: true),
                    label: '分类'),
                //购物车
                BottomNavigationBarItem(
                    icon: Image.asset('assets/cart_nor.png',
                        gaplessPlayback: true),
                    activeIcon: Image.asset('assets/cart_sel.png',
                        gaplessPlayback: true),
                    label: '购物车'),
                //我的
                BottomNavigationBarItem(
                    icon: Image.asset('assets/mine_nor.png',
                        gaplessPlayback: true),
                    activeIcon: Image.asset('assets/mine_sel.png',
                        gaplessPlayback: true),
                    label: '我的'),
              ],
            )));
  }
}
